package cn.moukou.tongji.ihealth.doctor.service;

import cn.moukou.tongji.ihealth.doctor.dao.CaseRecordFileMapper;
import cn.moukou.tongji.ihealth.doctor.dao.CaseRecordMapper;
import cn.moukou.tongji.ihealth.doctor.pojo.CaseRecordFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CaseRecordFileService {

    @Autowired
    CaseRecordFileMapper caseRecordFileMapper;

    public int deleteOne(String filepath) {
        return caseRecordFileMapper.deleteById(filepath);
    }

    public int insertOne(Long cid, String did, String filepath, String filename) {

        if(caseRecordFileMapper.selectById(filepath)!=null) {
            return 1;
        }

        CaseRecordFile caseRecordFile = new CaseRecordFile();
        caseRecordFile.setCid(cid);
        caseRecordFile.setDid(did);
        caseRecordFile.setFilepath(filepath);
        caseRecordFile.setFilename(filename);
        return caseRecordFileMapper.insert(caseRecordFile);
    }

    public List<CaseRecordFile> getFilesByCid(Long cid) {
        Map<String, Object> map = new HashMap<>();
        map.put("cid", cid);
        List<CaseRecordFile> recordFiles = caseRecordFileMapper.selectByMap(map);
        return recordFiles;
    }

}
